package com.example.function.integration.controller;

import com.example.function.integration.config.EmailConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Description： 邮件发送控制层
 * @Author： fengcheng
 * @Date： 2024/10/9 10:04
 */
@RestController
@RequestMapping("/email")
public class EmailSendController {

    @Autowired
    private EmailConfig emailConfig;

    public static Logger logger = LoggerFactory.getLogger(EmailSendController.class);

    /**
     * @Description：测试邮件发送功能
     * @Author：fengcheng
     * @Date：2024/10/9 10:18
     * @Param：emailParam
     * @Param：toUserEmail
     * @ParamsType：[java.util.Map<java.lang.String,java.lang.String>]
     * @Return：java.lang.Boolean
     */
    @PostMapping("/testSendEmail")
    public Boolean testSendEmail(@RequestBody Map<String, String> emailParam) {
        logger.info("testSendEmail.开始发送邮件:{}", emailParam);
        emailConfig.sendEmail(emailConfig.getMimeMessage(), emailParam);
        logger.info("testSendEmail.发送邮件结束:{}", emailParam);
        return true;
    }
}
